home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_08 / gottner / hashmap.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-04  |  1.2 KB  |  45 lines

  1. /*----------------------------------------*
  2.  * hashhmap.cc --
  3.  *    Implementation of the Map<> template
  4.  */
  5. template <class KEY, class VAL>
  6. void Map<KEY, VAL>::CreateKeyVal(
  7.                         const Map<KEY, VAL> & theDict,
  8.                         const KEY &           theKey,
  9.                         KEY *&                keyCopy,
  10.                         VAL *&                newValue)
  11. {
  12.     keyCopy  = new KEY(theKey);
  13.     newValue = new VAL(theDict.default_value);
  14. }
  15.  
  16.  
  17. template <class KEY, class VAL>
  18. void Map<KEY, VAL>::DestroyKeyVal(KEY *key, VAL *value)
  19. {
  20.     delete key;
  21.     delete value;
  22. }
  23.  
  24.  
  25. template <class KEY, class VAL>
  26. int Map<KEY, VAL>::CmpKeys(const KEY &a, const KEY &b)
  27. {
  28.     return a == b;
  29. }
  30.  
  31.  
  32. template <class KEY, class VAL>
  33. Map<KEY, VAL>::Map(
  34.                   unsigned    (*hash)(const KEY &),
  35.                   const VAL & def_val,
  36.                   size_t      dict_size)
  37.  
  38.   : VPmap(dict_size,
  39.           KeyHashProc(hash),
  40.           KeyCompareEqProc(Map<KEY, VAL>::CmpKeys),
  41.           KeyValCreateProc(Map<KEY, VAL>::CreateKeyVal),
  42.           KeyValDestroyProc(Map<KEY, VAL>::DestroyKeyVal)),
  43.  
  44.     default_value(def_val) { }
  45.